Open
Conversation
K-odesome
reviewed
Mar 25, 2024
internal/codegen/golang/gen.go
Outdated
| if !strings.Contains(qsql, "SELECT") { | ||
| continue | ||
| } | ||
| if strings.Contains(qsql, "UPDATE") || strings.Contains(qsql, "INSERT") { |
There was a problem hiding this comment.
Can we also check for delete as well if queries have
something like
DELETE FROM your_table
WHERE some_condition IN (
SELECT some_column
FROM another_table
WHERE your_condition
);
K-odesome
reviewed
Mar 25, 2024
| rq = append(rq, q) | ||
| } | ||
| return rq | ||
| } |
There was a problem hiding this comment.
Can we do it something like this
func readOnly(queries []Query) []Query {
var rq []Query
for _, q := range queries {
if !q.hasRetType() {
continue
}
qsql := strings.ToUpper(q.SQL)
if !containsOnlyAllowedKeywords(qsql) {
continue
}
rq = append(rq, q)
}
return rq
}
func containsOnlyAllowedKeywords(query string) bool {
keywords := []string{"INSERT", "UPDATE", "DELETE","CREATE","ALTER"} // and the other keywords
for _, keyword := range keywords {
if strings.Contains(qsql, keyword) {
return false
}
}
return true
}
So that we can define the list of exluded words
Author
There was a problem hiding this comment.
queries wont/shouldn't have ddl. so we can rule out CREATE and ALTER
Author
|
hey @kyleconroy can i get a review on this? |
Author
|
@kyleconroy is this good to go? |
Author
|
bump @kyleconroy |
|
bump @kyleconroy I am also interested in this feature! @jarri-abidi maybe you want to make the piplines work, I think thats the reason why its not being merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solution for #3187
no support for pgx
sorry if the code looks messy at all - open to feedback